#ifndef INC_PROCESSORID_HPP
#define INC_PROCESSORID_HPP

#include <vector>


//	Defines
//	==========================================================================
#define uint8 unsigned char

// Vendors
#define	VENDOR_GENUINEINTEL 0x756E6547
#define VENDOR_AUTHENTICAMD 0x68747541
#define VENDOR_CYRIX		0x69727943


//	Enums
//	==========================================================================
enum EVendor
{
	INTEL=0,
	AMD,
	MAX_VENDORS
};

enum EProcessorCapabilities
{
	FPU			= 0,		//	Floating Point Unit
	VME			= 1,		//	Virtual Mode Extensions
	DE			= 2,		//	Debugging Extensions
	PSE			= 3,		//	Page Size Extensions
	TSC			= 4,		//	Time Stamp Counter
	MSR			= 5,		//	Model-Specific Registers
	PAE			= 6,		//	Physical Address Extensions
	MCE			= 7,		//	Machine Check Exception
	CX8			= 8,		//	COMPXCHG8B_Instruction
	APIC		= 9,		//	Advanced Programmable Interrupt Controller
							//	reserved
	SEP         = 11,       //	Fast System Calls
	MTRR        = 12,       //	Memory Type Range Registers
	PGE         = 13,       //	Page Global Enable
	MCA         = 14,       //	Machine Check Architecture
	CMOV        = 15,       //	Conditional move-instruction
	PAT         = 16,       //	Page Attribute Table
	PSE36       = 17,       //	36-bit Page Size Extensions
	PSN         = 18,       //	Processor Serial Number
	CLFL        = 19,       //	CLFLUSH - fixme? 
							//	reserved
	DTES        = 21,       //	Debug Trace and EMON Store MSRs
	ACPI        = 22,       //	Thermal Cotrol MSR
	MMX			= 23,
	FXSR        = 24,       //	Fast floating point save/restore
	SSE			= 25,		//	Streaming SIMD Extensions
	SSE2		= 26,		//	Streaming SIMD Extensions 2
	SS          = 27,       //	Selfsnoop
	HTT         = 28,       //	Hyper-Threading Technology
	TM1         = 29,       //	Thermal Interrupts, Status MSRs
	IA64        = 30,       //	IA-64 (64-bit Intel CPU)
	PBE         = 31,       //	Pending Break Event
};

class ProcessorID
{
public:
	ProcessorID() :
	  m_L1CacheSizeKB(0),
	  m_L2CacheSizeKB(0)
	{}

	bool GetInfo( void );
	std::string PrintData( void );
	std::string Print( void );

	EVendor						m_VendorID;
	uint8						m_Revision;
	uint8						m_Model;
	uint8						m_Family;
	uint8						m_Type;

	// Seems Intel specific
	uint8						m_ExtendedModel;
	uint8						m_ExtendedFamily;
	uint8						m_Brand;

	unsigned int				m_L1CacheSizeKB;
	unsigned int				m_L2CacheSizeKB;

	std::vector<bool>			m_Capabilities;
	std::string					m_VendorCPUName;

	struct regData {
		unsigned long eax, ebx, ecx, edx;
	};
	std::vector<regData>		m_Data;
	std::vector<regData>		m_DataExtended;

private:
	bool CheckCPUIDPresence( void );
	void GetAllData( void );

	void SetVendorID( void );
	void SetProcType( void );

	void SetProcTypeAMD( void );
	void SetProcTypeIntel( void );

	void SetCapabilities( void );

	void SetCacheInformation( void );

};

#endif // INC_PROCESSORID_HPP


//------------------------------------------------------------------------
// Copyright (c) 2005 Rick Appleton
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
//    claim that you wrote the original software. If you use this software
//    in a product, an acknowledgment in the product documentation would
//    be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
//    be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
//    distribution.
//
// Rick Appleton
// www.daedalus-development.net
//------------------------------------------------------------------------
